package dryven.model.validation;

import java.util.HashMap;
import java.util.Map;

public class MapErrorMessageCollection implements ErrorMessageCollection {

	private Map<String, ErrorMessage> _messages = new HashMap<String, ErrorMessage>();
	
	@Override
	public ErrorMessage getMessageByName(String name) {
		return _messages.get(name);
	}

	@Override
	public Iterable<String> getMessageNames() {
		return _messages.keySet();
	}
	
	public void addMessage(String name, ErrorMessage msg) {
		_messages.put(name, msg);
	}

	@Override
	public void merge(ErrorMessageCollection b) {
		if(b instanceof MapErrorMessageCollection) {
			MapErrorMessageCollection mb = (MapErrorMessageCollection)b;
			_messages.putAll(mb._messages);
		} else {
			for (String s : b.getMessageNames()) {
				addMessage(s, b.getMessageByName(s));
			}
		}
	}

}
